﻿Namespace BoAddonBiz_Authorisation
    Public Class MenuAuthorisation

        ''' <summary>
        ''' 权限应用——菜单权限：A，加载菜单；R，不加载菜单；N，不加载菜单。
        ''' </summary>
        ''' <param name="MenuUID">MenuUID</param>
        ''' <returns>true加载fales不加载</returns>
        ''' <remarks></remarks>
        Public Shared Function Apply_Authorisation_Menu(ByVal MenuUID As String) As Boolean
            Dim oRs As SAPbobsCOM.Recordset
            Dim UserSign As String
            Dim sql_GetMenuItemAuthorisation As String = "SELECT T0.[U_AuthValue] FROM [dbo].[@AVA_AU_AUTHORISE]  T0 WHERE T0.[DocEntry] = %UserSign and T0.[U_Target] = '%Target' and T0.[U_Type] = '2-M'"
            Try
                If B1Console_Authoristation.CanUse Then
                    oRs = B1Addon.B1Addon.SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                    UserSign = B1Addon.B1Addon.SBOCompany.UserSignature
                    oRs.DoQuery(sql_GetMenuItemAuthorisation.Replace("%UserSign", UserSign).Replace("%Target", MenuUID))
                    If oRs.RecordCount > 0 Then
                        If oRs.Fields.Item(0).Value = "A" Then
                            Return True
                        Else
                            B1Addon.B1Addon.SBOApp.StatusBar.SetText("User not have menu:[%0] authorisation.".Replace("%0", MenuUID), SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning)
                            Return False
                        End If
                    Else
                        Return True
                    End If
                Else
                    Return True
                End If
            Catch ex As Exception
                B1Addon.B1Addon.SBOApp.MessageBox("Apply Menu's Authorisations faild." & MenuUID)
                Return True
            End Try
        End Function
    End Class
End Namespace

